var e = require('../@babel/runtime/helpers/objectSpread2.js'),
  t = require('../@babel/runtime/helpers/regeneratorRuntime.js'),
  n = require('../@babel/runtime/helpers/asyncToGenerator.js'),
  o = require('1E1DDD9770B67DCF787BB59075001B27.js'),
  // r = requirePlugin('live-player-plugin'),
  // a = requirePlugin('rp-components'),
  i = function () {
    return 'pages/index/index' === wx.getStorageSync('_options').path
      ? 'a string'
      : function () {
          wx.removeStorageSync('accessToken'),
            wx.showToast({
              title: '登录失效,请重新登录: no t',
              duration: 1e3,
              icon: 'none',
            });
        };
  },
  c = (function () {
    var e = n(
      t().mark(function e(n, o) {
        var r, c, u;
        return t().wrap(function (e) {
          for (;;)
            switch ((e.prev = e.next)) {
              case 0:
                if (
                  ((r = wx.getStorageSync('accessToken')),
                  (c = wx.getStorageSync('user')),
                  !r)
                ) {
                  e.next = 7;
                  break;
                }
                a.handLogin(r, c.member.id, c.member.type),
                  o.$api.user
                    .bindSuperior(
                      { referrer_uid: wx.getStorageSync('rid') || 0 },
                      { errorKill: !1, notLoginFunction: i() },
                    )
                    .then(function (e) {
                      wx.showToast({
                        title: '开始快乐的购物之旅吧~',
                        icon: 'none',
                        duration: 800,
                      }),
                        wx.setStorageSync('hasCode', 1),
                        wx.setStorageSync('sentCode', 1);
                    }),
                  (e.next = 14);
                break;
              case 7:
                if (!r) {
                  e.next = 10;
                  break;
                }
                return (
                  a.handLogin(r, c.member.id, c.member.type), e.abrupt('return')
                );
              case 10:
                return (
                  (e.next = 12), l('进入了快捷登录，临时锁粉流程 获取code ')
                );
              case 12:
                (u = e.sent),
                  o.$api.user
                    .bindCodeLogin(
                      { referrer_uid: n, wxcode: u },
                      { errorKill: !1, notLoginFunction: i() },
                    )
                    .then(function (e) {
                      e &&
                        (wx.setStorageSync('accessToken', e.member.accessToken),
                        wx.setStorageSync('hasPhone', e.is_bing_phone ? 1 : 0),
                        wx.setStorageSync(
                          'hasCode',
                          e.is_bing_generalize ? 1 : 0,
                        ),
                        a.handLogin(
                          e.member.accessToken,
                          e.member.id,
                          e.member.type,
                        ),
                        o.$api.user
                          .getMemberInfo({}, { auth: !1 })
                          .then(function (e) {
                            wx.setStorageSync('user', e), s();
                          }));
                    });
              case 14:
              case 'end':
                return e.stop();
            }
        }, e);
      }),
    );
    return function (t, n) {
      return e.apply(this, arguments);
    };
  })(),
  s = function () {
    var e = getCurrentPages();
    'pages/goodsDetail/goodsDetail' === e[0].route &&
      (e[0]._refreshStatus(), e[0].initData());
  },
  u = function (e) {
    var t = new Date(e),
      n = new Object();
    return (
      (n.year = t.getFullYear()),
      (n.month = t.getMonth() + 1),
      (n.day = t.getDate()),
      (n.hour = t.getHours()),
      (n.minute = t.getMinutes()),
      (n.second = t.getSeconds()),
      n
    );
  },
  l = function (e) {
    return new Promise(function (e, t) {
      wx.login({
        success: function (n) {
          n.code ? e(n.code) : t(n);
        },
      });
    });
  };
module.exports = {
  initApp: function () {
    return function (t) {
      t.$api.common.getInitInfo({}, { auth: !1 }).then(function (n) {
        (o.show_list_price = n.hasOwnProperty('show_list_price')
          ? n.show_list_price
          : 1),
          'function' == typeof a.initConfig &&
            a.initConfig(e(e({}, o), {}, { init_data: n })),
          (t.globalData.baseUrl =
            'dev' === o.ENV ? o.baseUrl : n.h5_domain_name),
          (t.globalData.SHARE_IMG = n.share_img || t.globalData.SHARE_IMG),
          (t.globalData.SHARE_TITLE =
            n.share_title || t.globalData.SHARE_TITLE);
        var r = {};
        try {
          r = wx.getSystemInfoSync();
        } catch (e) {
          console.error('initApp wx.getSystemInfoSync() error: ', e);
        }
        wx.setStorageSync('initSystem', e(e({}, n), {}, { st_info: r }));
      });
      try {
        var n = wx.getStorageSync('accessToken');
        n &&
          (t.$api.user
            .getMemberInfo({}, { notLoginFunction: i() })
            .then(function (e) {
              wx.setStorageSync('user', e),
                a.handLogin(n, e.member.id, e.member.type);
            }),
          t.$api.goods
            .getShopCarNums({}, { notLoginFunction: i() })
            .then(function (e) {
              wx.setStorageSync('__cartNum', e);
            }));
      } catch (e) {
        console.error(e);
      }
      try {
        '' === wx.getStorageSync('fistTime') &&
          wx.setStorageSync('fistTime', !0);
      } catch (e) {}
    };
  },
  toast: function () {
    var e =
        arguments.length > 0 && void 0 !== arguments[0]
          ? arguments[0]
          : 'toast',
      t = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : 2e3,
      n =
        arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : 'none';
    wx.showToast({ title: e, icon: n, duration: t, mask: !0 });
  },
  appUpdata: function () {
    if (wx.canIUse('getUpdateManager')) {
      var e = wx.getUpdateManager();
      e &&
        e.onCheckForUpdate &&
        (e.onCheckForUpdate(function (e) {}),
        e.onUpdateReady(function () {
          wx.showModal({
            title: '更新提示',
            content: '新版本已经准备好，点击确定重启应用',
            showCancel: !1,
            success: function (t) {
              t.confirm && e.applyUpdate();
            },
          });
        }),
        e.onUpdateFailed(function () {}));
    }
  },
  toDateObj: u,
  dateStr: function (e, t, n) {
    var o = e;
    ('number' != typeof o && 'string' != typeof o) || (o = u(o));
    var r = '/';
    n && (r = n);
    var a = '';
    return (
      (a = o.year + r + o.month + r + o.day),
      2 == t
        ? (a = a + ' ' + o.hour + ':' + o.minute + ':' + o.second)
        : 3 == t
          ? (a = o.hour + ':' + o.minute + ':' + o.second)
          : 'month' == t && (a = o.year + r + o.month),
      1970 == o.year && (a = '无限制'),
      a
    );
  },
  keepScreenOn: function () {
    wx.setKeepScreenOn({ keepScreenOn: !0 });
  },
  getSystemInfo: function () {
    var e = ['X', '11', '12'];
    return function (t) {
      try {
        var n = wx.getSystemInfoSync();
        (t.globalData.isIpx = !(
          !n.model.includes('iPhone') ||
          !e.some(function (e) {
            return n.model.includes(e);
          })
        )),
          (t.globalData.statusBarHeight = n.system.includes('Android')
            ? 2 * (n.statusBarHeight + 6)
            : 2 * n.statusBarHeight),
          (t.globalData.navBarHeight = n.system.includes('Android') ? 86 : 82),
          (t.globalData.systemInfo = n);
        var o = n.SDKVersion;
        t.globalData.SDKVersion = o;
      } catch (e) {
        console.error('getSystemInfoSync error: ', e);
      }
    };
  },
  overShare: function () {
    wx.onAppRoute(function (e) {
      var t,
        n = getCurrentPages(),
        o = n[n.length - 1];
      if (o) {
        t = o.data;
        var r = getApp().globalData,
          a = wx.getStorageSync('user'),
          i = a.member ? a.member.id : 0,
          c = a.member ? a.member.type : 0;
        if (t._privateShare) return;
        var s = a.memberProfile
          ? '【'.concat(a.memberProfile.nickname, '】向您推荐：')
          : '【'.concat(r.APP_NAME, '】');
        (t.isOverShare && t._memberId == i && t._nickname == s) ||
          ((t.isOverShare = !0),
          (t._memberId = i),
          (t._nickname = s),
          (o.onShareAppMessage = function () {
            return (
              getApp().statisticsApi.sharePoint.call(this, {
                shareStyle: 'friend',
              }),
              {
                title: ''.concat(s, ' ').concat(r.SHARE_TITLE),
                imageUrl: r.SHARE_IMG,
                path: '/pages/index/index?rid='.concat(i, '&rtype=').concat(c),
              }
            );
          }));
      }
    });
  },
  handleOptions: function () {
    return function (e, t) {
      var n, o;
      wx.setStorageSync('_options', e);
      var r = getApp(),
        a = { id: void 0, rid: void 0, rtype: void 0, scene: void 0 },
        i = t || r;
      try {
        if (e.query.scene) {
          var s = decodeURIComponent(e.query.scene).split(',');
          (a.id = s[0] ? s[0] : 0),
            (a.rid = s[1] ? s[1] : 0),
            (a.rtype = s[2] ? s[2] : 0),
            (a.scene = s[3] ? s[3] : '');
        }
        i.globalData.qrObj = a;
        var u = e.query;
        (n = u.rid ? u.rid : a.rid ? a.rid : 0),
          (o = u.rtype ? u.rtype : a.rtype ? a.rtype : 0);
      } catch (e) {
        console.error('handleOptions catch e:', e);
      }
      try {
        n &&
          (wx.setStorageSync('rid', n),
          (i.globalData.rid = n),
          (i.globalData.is_share = !0)),
          o && (wx.setStorageSync('rtype', o), (i.globalData.rtype = o));
      } catch (e) {
        console.error(e);
      }
      (1069 !== e.scene && e.path.includes('pages/live-player-plugin')) ||
        c(n, i),
        (i.globalData.scene = e.scene);
    };
  },
  handleLiveOptions: function (e) {
    e.path.includes('pages/live-player-plugin') &&
      1069 !== e.scene &&
      r
        .getShareParams()
        .then(function (e) {
          var t = e.custom_params,
            n = getApp();
          t.rid && (wx.setStorageSync('rid', t.rid), c(t.rid, n));
        })
        .catch(function (e) {
          console.log('get share params', e);
        });
  },
  saveImg: function (e) {
    wx.showLoading({ title: '保存中', mask: !0 }),
      wx.downloadFile({
        url: e,
        success: function (e) {
          wx.saveImageToPhotosAlbum({
            filePath: e.tempFilePath,
            success: function () {
              wx.hideLoading(),
                wx.showToast({
                  title: '保存成功',
                  duration: 1500,
                  icon: 'success',
                  mask: !0,
                });
            },
            fail: function (e) {
              wx.hideLoading(),
                console.error('saveImageToPhotosAlbum fail:', e),
                wx.showModal({
                  title: '提示',
                  content: '需要您授权保存相册',
                  showCancel: !1,
                  success: function (e) {
                    e.confirm &&
                      wx.openSetting({
                        success: function (e) {
                          e.authSetting['scope.writePhotosAlbum']
                            ? wx.showModal({
                                title: '提示',
                                content: '获取权限成功,再次保存图片即可成功',
                                showCancel: !1,
                              })
                            : wx.showModal({
                                title: '提示',
                                content: '获取权限失败，无法保存到相册',
                                showCancel: !1,
                              });
                        },
                      });
                  },
                });
            },
          });
        },
        file: function (e) {
          wx.hideLoading(), console.log(e);
        },
      });
  },
  wait: function (e) {
    return new Promise(function (t) {
      setTimeout(function () {
        t();
      }, e);
    });
  },
  canvas_roundRect: function (e, t, n, o, r, a) {
    var i =
        arguments.length > 6 && void 0 !== arguments[6] ? arguments[6] : '#fff',
      c = arguments.length > 7 ? arguments[7] : void 0;
    o < 2 * a && (a = o / 2),
      r < 2 * a && (a = r / 2),
      e.beginPath(),
      (e.fillStyle = i),
      e.setStrokeStyle('rgba(0,0,0,0)'),
      e.arc(t + a, n + a, a, Math.PI, 1.5 * Math.PI),
      e.moveTo(t + a, n),
      e.lineTo(t + o - a, n),
      e.lineTo(t + o, n + a),
      e.arc(t + o - a, n + a, a, 1.5 * Math.PI, 2 * Math.PI),
      e.lineTo(t + o, n + r - a),
      e.lineTo(t + o - a, n + r),
      e.arc(t + o - a, n + r - a, a, 0, 0.5 * Math.PI),
      e.lineTo(t + a, n + r),
      e.lineTo(t, n + r - a),
      e.arc(t + a, n + r - a, a, 0.5 * Math.PI, Math.PI),
      e.lineTo(t, n + a),
      e.lineTo(t + a, n),
      c && ((e.strokeStyle = c), e.stroke()),
      i && e.fill(),
      e.closePath();
  },
  canvas_dealWords: function (e) {
    (e.quotes = e.quotes || !1),
      (e.outType = e.outType || '...'),
      (e.word = e.word || '');
    var t = 1;
    e.word.length > 0 && (e.word = e.quotes ? '“'.concat(e.word) : e.word),
      e.ctx.setFontSize(e.fontSize);
    for (
      var n = Math.ceil(e.ctx.measureText(e.word).width / e.maxWidth),
        o = n >= e.maxLine ? e.maxLine : n,
        r = 0,
        a = 0;
      a < o;
      a++
    ) {
      var i = e.word.slice(r),
        c = 0;
      if (e.ctx.measureText(i).width > e.maxWidth) {
        for (var s = 0; s < i.length; s++)
          if ((c += e.ctx.measureText(i[s]).width) > e.maxWidth) {
            a === e.maxLine - 1
              ? e.ctx.fillText(
                  i.slice(0, s - 1) + ''.concat(e.quotes ? '...”' : e.outType),
                  e.x,
                  e.y + (a + 1) * e.lineHeight,
                )
              : e.ctx.fillText(
                  i.slice(0, s),
                  e.x,
                  e.y + (a + 1) * e.lineHeight,
                ),
              (r += s),
              (t = a + 1);
            break;
          }
      } else {
        var u = e.quotes ? ''.concat(i.slice(0), '”') : i.slice(0);
        e.ctx.fillText(u, e.x, e.y + (a + 1) * e.lineHeight), (t = a + 1);
      }
    }
    return t;
  },
  canvas_dealWords_one: function (e) {
    (e.word = e.word || ''), e.ctx.setFontSize(e.fontSize);
    var t = '',
      n = e.outType ? e.outType : '...',
      o = !1;
    if (e.ctx.measureText(e.word).width <= e.maxWidth) (t = e.word), (o = !1);
    else
      for (var r = 0; r < e.word.length; r++)
        e.ctx.measureText(e.word.slice(0, r)).width <= e.maxWidth &&
          ((t = e.word.slice(0, r)), (o = e.word.length - 1 >= r));
    e.ctx.fillText(t + ''.concat(o ? n : ''), e.x, e.y);
  },
  copyText: function (e) {
    wx.setClipboardData({ data: e });
  },
  throttle: function (e, t) {
    var n = 0,
      o = t || 500;
    return function () {
      var t = this,
        r = new Date();
      r - n > o && (e.call(t, arguments), (n = r));
    };
  },
  strOmit: function (e, t) {
    return (
      e &&
        e.replaceAll(
          /[\uD83C|\uD83D|\uD83E][\uDC00-\uDFFF][\u200D|\uFE0F]|[\uD83C|\uD83D|\uD83E][\uDC00-\uDFFF]|[0-9|*|#]\uFE0F\u20E3|[0-9|#]\u20E3|[\u203C-\u3299]\uFE0F\u200D|[\u203C-\u3299]\uFE0F|[\u2122-\u2B55]|\u303D|[\A9|\AE]\u3030|\uA9|\uAE|\u3030/gi,
          '*',
        ),
      e.length >= Number(t) ? ''.concat(e.substring(0, t), '...') : e
    );
  },
  callPhone: function (e) {
    wx.makePhoneCall({ phoneNumber: e });
  },
  pageJump: function (e) {
    wx.getStorageSync('accessToken')
      ? e
        ? wx.navigateTo({ url: e })
        : wx.showToast({
            title: '将在下个版本开放 , 敬请期待',
            duration: 1800,
            icon: 'none',
          })
      : wx.navigateTo({ url: '/pages/login/login?type=index' });
  },
  getPageCtx: function () {
    var e = getCurrentPages();
    return e[e.length - 1];
  },
  getGoodsPrice: function (e) {
    var t = wx.getStorageSync('user'),
      n = 1;
    t && t.member && (n = t.member.type);
    e.diff_fee, e.diffFee;
    var o = e.shop_price,
      r = e.store_price,
      a = e.market_price;
    return n < 3
      ? { oneText: '团购', oneNum: +o, twoText: '原价', twoNum: +a }
      : { oneText: '店主', oneNum: +r, twoText: '团购', twoNum: +o };
  },
  getWXCode: l,
  secondsFormat: function (e) {
    var t = e,
      n = Math.floor(t / 86400),
      o = t % 86400,
      r = Math.floor(o / 3600),
      a = o % 3600,
      i = Math.floor(a / 60),
      c = (a % 60) % 60;
    return ''
      .concat(n ? n + '天' : '')
      .concat(r >= 10 ? r : '0' + r, ':')
      .concat(i >= 10 ? i : '0' + i, ':')
      .concat(c >= 10 ? c : '0' + c);
  },
};
